<?
$r = "../";
require_once($r."_engine/header_nocache.php");
require_once($r."_engine/functions.php");
require_once($r."_engine/c_news.php");

if (@$todo == "update" || @$todo == "add")
{
	// Convert form data to DB representation
	$f_dt = @strtotime($f_dt);
	$f_option_is_archived	= isset($f_option_is_archived) ? 1 : 0;
	$f_option_show_on_fp	= isset($f_option_show_on_fp) ? 1 : 0;


	// List of fields to be update in the database
	get_form_values($values, array(
		"dt", "option_is_archived", "option_show_on_fp",
		"title_fp", "title", "text",
	));

	$news = new CNews();

	if (@$todo == "update") 
	{
		$news->id = $id;
		$news->Update($values);
	}
	else 
	{
		$news->Insert($values);
	}
}
else if (@$todo == "remove")
{
	$g_st_news->Delete(@$f_ids);
}
else if (@$todo == "archive")
{
	$u["option_is_archived"] = 1;
	$g_st_news->Update($u, @$f_ids);
}
else 
{
	var_dump($todo);
	die("Incorrect data - todo.");
}

generate_html_redirect("news.php");
?>